package haust;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;

import static org.lwjgl.opengl.GL11.*;


public class MainMenu implements Client
{
	private Vec3 buttonDemofrom;
	private Vec3 buttonDemosize;
	
	private Vec3 buttonSndfrom;
	private Vec3 buttonSndsize;
	
	private Vec3 buttonExitfrom;
	private Vec3 buttonExitsize;
	
	private boolean exitFlag = false;
	
	public MainMenu(){		
	}

	@Override
	public int Initialize() {
		buttonDemofrom = new Vec3(300,250,0);
		buttonDemosize = new Vec3(150,75,0);
		
		buttonSndfrom = new Vec3(300,150,0);
		buttonSndsize = new Vec3(150,75,0);
		
		buttonExitfrom = new Vec3(300,50,0);
		buttonExitsize = new Vec3(150,75,0);
		
		int xValue = Display.getWidth() / 2 - 75;
		buttonDemofrom.setX( xValue );
		buttonSndfrom.setX( xValue );
		buttonExitfrom.setX( xValue );
		
		
		return 1;
	}

	@Override
	public void Deinitialize() {		
	}

	int x=0, y=0;
	@Override
	public void Update(float fDelta) {
		if( Mouse.isButtonDown(0) )
		{
			x = Mouse.getX();
			y = Mouse.getY();		
			
			if( x > buttonDemofrom.getX() && y > buttonDemofrom.getY() )
			{
				if( x - buttonDemofrom.getX() < buttonDemosize.getX() && y - buttonDemofrom.getY() < buttonDemosize.getY() )
					Entry.Run( new DemoScene() );
			}
			
			if( x > buttonSndfrom.getX() && y > buttonSndfrom.getY() )
			{
				if( x - buttonSndfrom.getX() < buttonSndsize.getX() && y - buttonSndfrom.getY() < buttonSndsize.getY() )
					Entry.Run( new SoundScene() );
			}
			
			if( x > buttonExitfrom.getX() && y > buttonExitfrom.getY() )
			{
				if( x - buttonExitfrom.getX() < buttonExitsize.getX() && y - buttonExitfrom.getY() < buttonExitsize.getY() )
					exitFlag = true;
			}
		}		
	}
	
	public void drawBox(Vec3 from, Vec3 size){
		glPushMatrix();
		glTranslatef(from.getX(), from.getY(), 0 );
		glLineWidth(10.0f);
		glBegin(GL_TRIANGLE_FAN);
			glColor3f(0,0,0); 
			glVertex2f(size.getX()/2, size.getY()/2);
			glColor3f(0,0,1);
			glVertex2f(0,0);
			glVertex2f(size.getX(), 0);
			glVertex2f(size.getX(), size.getY());
			glVertex2f(0,size.getY());
			glVertex2f(0,0);
		glEnd();
		glLineWidth(1.0f);
		glPopMatrix();
	}

	@Override
	public void Render(){
		Entry.pushOrtho();
			glDisable(GL_DEPTH_TEST);
			drawBox(buttonDemofrom, buttonDemosize );
			drawBox(buttonSndfrom,  buttonSndsize );
			drawBox(buttonExitfrom, buttonExitsize );

			FontManager.drawTextFont("Demo", buttonDemofrom.getX() + 40,300);
			FontManager.drawTextFont("Sound", buttonSndfrom.getX() + 40,200);
			FontManager.drawTextFont("Exit", buttonExitfrom.getX() + 40, 100);
		Entry.popOrtho();
	}

	@Override
	public int getRenderMode() {
		return 0;
	}

	@Override
	public boolean getExitFlag() {
		return exitFlag;
	}	
}